package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysSinger;
import com.ruoyi.system.service.ISysSingerService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysSongMapper;
import com.ruoyi.system.domain.SysSong;
import com.ruoyi.system.service.ISysSongService;

/**
 * 歌曲信息Service业务层处理
 *
 * @author Johnson
 * @date 2025-04-30
 */
@Service
@RequiredArgsConstructor
public class SysSongServiceImpl implements ISysSongService {

    private final SysSongMapper sysSongMapper;

    private final ISysSingerService sysSingerService;

    /**
     * 查询歌曲信息
     *
     * @param songId 歌曲信息主键
     * @return 歌曲信息
     */
    @Override
    public SysSong selectSysSongBySongId(Long songId) {
        return sysSongMapper.selectSysSongBySongId(songId);
    }

    /**
     * 查询歌曲信息列表
     *
     * @param sysSong 歌曲信息
     * @return 歌曲信息
     */
    @Override
    public List<SysSong> selectSysSongList(SysSong sysSong) {
        return sysSongMapper.selectSysSongList(sysSong);
    }

    /**
     * 新增歌曲信息
     *
     * @param sysSong 歌曲信息
     * @return 结果
     */
    @Override
    public int insertSysSong(SysSong sysSong) {
        if (sysSong.getArtistName() != null) {
            SysSinger sysSinger = sysSingerService.selectSysSingerBySingerName(sysSong.getArtistName());
            sysSong.setArtistId(sysSinger.getSingerId());
        }
        sysSong.setCreateTime(DateUtils.getNowDate());
        return sysSongMapper.insertSysSong(sysSong);
    }

    /**
     * 修改歌曲信息
     *
     * @param sysSong 歌曲信息
     * @return 结果
     */
    @Override
    public int updateSysSong(SysSong sysSong) {
        sysSong.setUpdateTime(DateUtils.getNowDate());
        return sysSongMapper.updateSysSong(sysSong);
    }

    /**
     * 批量删除歌曲信息
     *
     * @param songIds 需要删除的歌曲信息主键
     * @return 结果
     */
    @Override
    public int deleteSysSongBySongIds(Long[] songIds) {
        return sysSongMapper.deleteSysSongBySongIds(songIds);
    }

    /**
     * 删除歌曲信息信息
     *
     * @param songId 歌曲信息主键
     * @return 结果
     */
    @Override
    public int deleteSysSongBySongId(Long songId) {
        return sysSongMapper.deleteSysSongBySongId(songId);
    }
}
